package com.labuladong;

import java.util.Objects;

/**
 * 项目名称: java_algorithm
 * @ClassName PreOrderTraversal
 * @Description 二叉树后序遍历
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2022/6/10 11:18
 */
public class PostOrderTraversal {

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode();
        treeNode.setLeftNode(new TreeNode() {{
            setTreeValue(2);
        }});
        treeNode.setRightNode(new TreeNode() {{
            setTreeValue(3);
        }});
        treeNode.setTreeValue(1);
        preOrder(treeNode);
    }

    public static void preOrder(TreeNode treeNode) {
        if (!Objects.isNull(treeNode)) {
            preOrder(treeNode.getLeftNode());
            preOrder(treeNode.getRightNode());
            System.out.println(treeNode.getTreeValue());
        }
    }

}
